package soar.template.springboot.service.client.configuration;

import javax.annotation.Resource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
import soar.template.springboot.service.client.appconfig.AppConfig;
import soar.template.springboot.service.rmi.hello.Hello;

@Configuration
public class MyRmiProxyConfiguration
{
    @Resource(name = "appconfig")
    private AppConfig appconfig;

    @Bean(name = "helloProxy")
    public RmiProxyFactoryBean helloProxy()
    {
        RmiProxyFactoryBean proxy = new RmiProxyFactoryBean();
        proxy.setServiceUrl(String.format("rmi://%s:%d/Hello",
                appconfig.rmi.host, appconfig.rmi.port));
        proxy.setServiceInterface(Hello.class);
        proxy.setLookupStubOnStartup(false);
        proxy.setRefreshStubOnConnectFailure(true);
        proxy.afterPropertiesSet();
        return proxy;
    }
}
